package com.deyuanyun.pic.pbf.domain;

import com.deyuanyun.pic.common.util.StringUtils;
import com.deyuanyun.pic.common.util.poi.annotation.ExcelWriteColumn;
import com.deyuanyun.pic.pbf.enumeration.DefectStateEnum;
import com.deyuanyun.pic.pbf.enumeration.RepairStateEnum;
import com.deyuanyun.pic.settings.domain.base.Attachment;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import com.deyuanyun.pic.settings.support.utils.BaseCodeUtils;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 非内检业务实体对象
 * @author lijun
 * @date 2016-06-22
 * 
 * History: [修改人][时间][修改描述]
 */
public class ExternalInspectionVo {


    /**
     * 主键
     */
    private String id;
    /**
     * 缺陷编号(自定义编号)
     */
    @ExcelWriteColumn
    private String customNumber;
    /**
     * 管道名称
     */
    @ExcelWriteColumn
    private String lineName;
    /**
     * 管道ID
     */
    private String pipeLineId;

    /**
     * 绝对距离（m）
     */
    @ExcelWriteColumn
    private Double mileage;
    /**
     * 最近参考点
     */
    @ExcelWriteColumn
    private String reference;
    /**
     * 相对最近参考点距离（m）
     */
    @ExcelWriteColumn
    private BigDecimal referenceDistance;
    /**
     * 上游环焊缝检测编号
     */
    @ExcelWriteColumn
    private String ugwNumber;
    /**
     * 相对上游环焊缝距离（m）
     */
    @ExcelWriteColumn
    private BigDecimal distancetougwNumber;
    /**
     * 埋深（m）
     */
    @ExcelWriteColumn
    private BigDecimal buriedDepth;
    /**
     * 非内检缺陷类型(链接CODE)
     */
    private String defectType;
    /**
     * 缺陷子类型
     */
    @ExcelWriteColumn
    private String featureSubtype;
    /**
     * 修复方法名称
     */
    @ExcelWriteColumn
    private String repairName;
    /**
     * 维修状态
     */
    private RepairStateEnum repairState;
    @ExcelWriteColumn
    private String repairState_lable;
    /**
     * 峰值深度（%wt）
     */
    @ExcelWriteColumn
    private BigDecimal maxDepth;
    /**
     * 长度（mm）
     */
    @ExcelWriteColumn
    private BigDecimal length;
    /**
     * 宽度（mm）
     */
    @ExcelWriteColumn
    private BigDecimal width;
    /**
     * 时钟位置（时:分）
     */
    @ExcelWriteColumn
    private String clock;
    /**
     * 创建备注
     */
    @ExcelWriteColumn
    private String createRemark;
    /**
     * 计算得到深度（深度=深度百分比*壁厚）
     */
    private BigDecimal depth;
    /**
     * 缺陷状态
     */
    private DefectStateEnum state;
    private String state_lable;
    /**
     * 缺陷来源
     */
    private String source;
    /**
     * 页面维修记录图标显示
     * 1--显示可查看
     * 2--显示只读
     * 3--显示可编辑
     */
    private int  repairShow;
    /**
     * 发现时间
     */
    private Date foundTime;

    private String foundTimeStr;

    /**
     * x
     */
    private BigDecimal x;

    /**
     * y
     */
    private BigDecimal y;

    /**
     * z
     */
    private BigDecimal z;
    /**
     * 驳回原因
     */
    private String remark;
    /**
     * 修复方法对应的修复表单
     */
    private String repairTab;
    /**
     * 非内检缺陷对应维修记录ID
     */
    private String repairRecordId;
    /**
     * 非内检测缺陷提交类型
     * 0--PC端   1--移动端
     */
    private int appartusType;
    /**
     * 缺陷检测报告path
     *
     * */
    private String reportPath;



    public String getFoundTimeStr() {
        return StringUtils.convertDateToString(foundTime,"yyyy-MM-dd");

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getLineName() {
        return lineName;
    }

    public String getPipeLineId() {
        return pipeLineId;
    }

    public void setPipeLineId(String pipeLineId) {
        this.pipeLineId = pipeLineId;
    }

    public void setLineName(String lineName) {
        this.lineName = lineName;
    }

    public String getDefectType() {
        return BaseCodeUtils.getName(defectType);
    }

    public void setDefectType(String defectType) {
        this.defectType = defectType;
    }

    public String getFeatureSubtype() {
        featureSubtype = StringUtils.isNotNullEmpty(featureSubtype) ? BaseCodeUtils.getName(featureSubtype) : getDefectType();
        return featureSubtype;
    }

    public void setFeatureSubtype(String featureSubtype) {
        this.featureSubtype = featureSubtype;
    }

    public String getUgwNumber() {
        return ugwNumber;
    }

    public void setUgwNumber(String ugwNumber) {
        this.ugwNumber = ugwNumber;
    }

    public String getDistancetougwNumber() {

        return distancetougwNumber != null?
                distancetougwNumber.setScale(3,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString() :null;
    }

    public void setDistancetougwNumber(BigDecimal distancetougwNumber) {
        this.distancetougwNumber = distancetougwNumber;
    }

    public DefectStateEnum getState() {
        return state;
    }

    public void setState(DefectStateEnum state) {
        this.state = state;
    }

    public String getSource() {
        return BaseCodeUtils.getName(source);
    }

    public void setSource(String source) {
        this.source = source;
    }

    public RepairStateEnum getRepairState() {
        return repairState;
    }

    public void setRepairState(RepairStateEnum repairState) {
        this.repairState = repairState;
    }

    public String getState_lable() {
        return state != null ? state.getValue() : null;
    }

    public String getRepairState_lable() {
        return  repairState != null ? repairState.getLabel() : null;
    }

    public Date getFoundTime() {
        return foundTime;
    }

    public void setFoundTime(Date foundTime) {
        this.foundTime = foundTime;
    }

    public BigDecimal getX() {
        return x;
    }

    public void setX(BigDecimal x) {
        this.x = x;
    }

    public BigDecimal getZ() {
        return z;
    }

    public void setZ(BigDecimal z) {
        this.z = z;
    }

    public BigDecimal getY() {
        return y;
    }

    public void setY(BigDecimal y) {
        this.y = y;
    }

    public BigDecimal getLength() {
        return length;
    }

    public void setLength(BigDecimal length) {
        this.length = length;
    }

    public BigDecimal getWidth() {
        return width;
    }

    public void setWidth(BigDecimal width) {
        this.width = width;
    }

    public String getMaxDepth() {

        return maxDepth != null ?maxDepth.setScale(1,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString():null;
    }

    public void setMaxDepth(BigDecimal maxDepth) {
        this.maxDepth = maxDepth;
    }

    public String getCustomNumber() {
        return customNumber;
    }

    public void setCustomNumber(String customNumber) {
        this.customNumber = customNumber;
    }

    public String getCreateRemark() {
        return createRemark;
    }

    public void setCreateRemark(String createRemark) {
        this.createRemark = createRemark;
    }

    public String getDepth() {

        return depth != null ?depth.setScale(0,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString():null;
    }

    public void setDepth(BigDecimal depth) {
        this.depth = depth;
    }

    public String getBuriedDepth() {
        return buriedDepth != null ? buriedDepth.setScale(3,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString() :null;
    }

    public void setBuriedDepth(BigDecimal buriedDepth) {
        this.buriedDepth = buriedDepth;
    }

    public String getClock() {
        return clock;
    }

    public void setClock(String clock) {
        this.clock = clock;
    }

    public Double getMileage() {

        return mileage != null ? mileage:null;
    }

    public void setMileage(Double mileage) {
        this.mileage = mileage;
    }
    public String getReference() {
        return reference;
    }

    public void setReference(String reference) {
        this.reference = reference;
    }

    public String getReferenceDistance() {
        return referenceDistance != null?
                referenceDistance.setScale(3,BigDecimal.ROUND_DOWN).stripTrailingZeros().toPlainString():null;
    }

    public void setReferenceDistance(BigDecimal referenceDistance) {
        this.referenceDistance = referenceDistance;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getRepairName() {
        return repairName;
    }

    public void setRepairName(String repairName) {
        this.repairName = repairName;
    }

    public String getRepairTab() {
        //返回修复表单对应的入口路径
        return repairTab != null ? RepairTabToEntry.get(repairTab) : repairTab;
    }

    public void setRepairTab(String repairTab) {
        this.repairTab = repairTab;
    }

    public int getAppartusType() {
        return appartusType;
    }

    public void setAppartusType(int appartusType) {
        this.appartusType = appartusType;
    }

    public String getReportPath() {
        return reportPath;
    }

    public void setReportPath(String reportPath) {
        this.reportPath = reportPath;
    }


    public int getRepairShow() {

        if ( "已发布".equals(getState_lable()) &&
                ("已修复".equals(getRepairState_lable()) || "修复中".equals(getRepairState_lable())))
        {
            repairShow = 1;

        }else if ( "已发布".equals(getState_lable()) && "待修复".equals(getRepairState_lable())
                && getAppartusType() == 0 )
        {
            repairShow = 3;
        }else
        {
            repairShow = 2;
        }


        return repairShow;
    }

    public String getRepairRecordId() {
        return repairRecordId;
    }

    public void setRepairRecordId(String repairRecordId) {
        this.repairRecordId = repairRecordId;
    }

    // 修复方法表单和入口路径对应Map
    private static  Map<String ,String> RepairTabToEntry =new HashMap(){
        {
            put("PIC_TDF_COAT_REPAIR","repairCoat");
            put("PIC_TDF_REPAIR_COMPOSITES","repairComposites");
            put("PIC_TDF_REPAIR_EPOXY_SLEEVE","repairEpoxySleeve");
            put("PIC_TDF_REPAIR_ABTYPE_SLEEVE","repairABTypeSleeve");
            put("PIC_TDF_REPAIR_REPLACE_PIPE","repairReplacePipe");
            put("PIC_TDF_REPAIR_OTHER","repairOther");
        }
    };


}
